<!--
* @description:新增货主合同管理
* @fileName: NewOwnerContract
* @author:石锦涛
* @date:2022-01-08
* @后台人员:石锦涛
-->
<template>
  <div>
    <!-- 新增货主合同 -->
    <div>
      <el-row :span="1">
        <el-col :span="3">合同标题:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TheContractTitle"></el-input
        ></el-col>
        <el-col :span="3">货主单位:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TheOwnerUnit"></el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">货主负责人:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.FreightPrincipal"></el-input
        ></el-col>
        <el-col :span="3">线路:</el-col>
        <el-col :span="7">
          <el-select v-model="jieshu.Line" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.LineName"
              :value="item.Id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">吨运价:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TonsOfFreight"></el-input
        ></el-col>
        <el-col :span="3">包车条件吨位:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.ConditionTonnage"></el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">包车金额:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.CharterValue"></el-input
        ></el-col>
        <el-col :span="3">经办人:</el-col>
        <el-col :span="7"><el-input v-model="jieshu.Agent"></el-input></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">签订时间:</el-col>
        <el-col :span="7"
          ><el-input type="date" v-model="jieshu.SignedTime"></el-input
        ></el-col>
        <el-col :span="3">合同金额:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TheContractAmount"></el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同标的或项目说明:</el-col>
        <el-col :span="12"
          ><el-input
            type="textarea"
            :rows="5"
            placeholder="请输入内容"
            v-model="jieshu.ProjectDescriptio"
          >
          </el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同主要条款/变更条款:</el-col>
        <el-col :span="12"
          ><el-input
            type="textarea"
            :rows="5"
            placeholder="请输入内容"
            v-model="jieshu.ChangeTheTerms"
          >
          </el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同文本(附件):</el-col>
        <el-col :span="12">
          <el-upload
            class="upload-demo"
            :on-success="upchuan"
            action="https://localhost:44399/api/app/file-common-app/uplosdqiniu"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              
            </div>
          </el-upload>
        </el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3"><el-button @click="Ti()">提交审批</el-button></el-col>
        <el-col :span="1"><el-button @click="fanhui()">取消</el-button></el-col>
        <el-col :span="3"
          ><el-button @click="addjiashu()">保存草稿</el-button></el-col
        >
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      jieshu: {
        TheShipContractNO: "",
        TheContractTitle: "",
        TheOwnerUnit: "",
        FreightPrincipal: "",
        Line: "",
        TonsOfFreight: "",
        ConditionTonnage: "",
        CharterValue: "",
        Agent: "",
        SignedTime: "",
        TheContractAmount: "",
        ProjectDescriptio: "",
        ChangeTheTerms: "",
        ContractTheText: "-",
        ContractStates: "0",
        TheApprover: "2",
        IsDelete: "0",
        AbnormityWarning:"0",
        FreightState:"0",
      },
      options: [],
    };
  },
  methods: {
    //显示线路
    xianlu() {
      this.$axios
        .get("https://localhost:44399/api/app/line-app/page")
        .then((res) => {
          this.options = res.data;
        });
    },
    //添加草稿
    addjiashu() {
      if (this.jieshu.TheContractTitle.length === 0) {
        alert("标题不能为空");
        return;
      }
      if (this.jieshu.TheOwnerUnit.length === 0) {
        alert("货主单位不能为空");
        return;
      }
      if (this.jieshu.FreightPrincipal.length === 0) {
        alert("货主负责人不能为空");
        return;
      }
      if (this.jieshu.Line.length === 0) {
        alert("线路不能为空");
        return;
      }

      if (this.jieshu.TonsOfFreight.length === 0) {
        alert("吨运价不能为空");
        return;
      }
      var retNum = /^\d+(\.\d+)?$/; //匹配数字匹配数字(包括小数)/^\d*$/
      if (!retNum.test(this.jieshu.TonsOfFreight)) {
        alert("吨运价只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.ConditionTonnage.length === 0) {
        alert("包车条件不能为空");
        return;
      }
      if (this.jieshu.CharterValue.length === 0) {
        alert("包车金额不能为空");
        return;
      }

      if (!retNum.test(this.jieshu.CharterValue)) {
        alert("包车金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.Agent.length === 0) {
        alert("经办人不能为空");
        return;
      }
      if (this.jieshu.SignedTime.length === 0) {
        alert("签订时间不能为空");
        return;
      }
      if (this.jieshu.TheContractAmount.length === 0) {
        alert("合同金额不能为空");
        return;
      }
      if (!retNum.test(this.jieshu.TheContractAmount)) {
        alert("合同金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.ProjectDescriptio.length === 0) {
        alert("合同标的或项目说明不能为空");
        return;
      }
      if (this.jieshu.ChangeTheTerms.length === 0) {
        alert("合同主要条款/变更条款不能为空");
        return;
      }
      this.$axios
        .post(
          "https://localhost:44399/api/app/new-owner-app/sianjia",
          this.jieshu
        )
        .then((res) => {
          if (res.data.Code > 0) {
            alert("添加成功");
            this.$router.push("/OwnerContractManagement");
          } else {
            alert("添加失败");
          }
        });
    },
    //上传
    upchuan(res) {
      if (res != null) {
        this.$message.success("上传文件成功");
        this.jieshu.ContractTheText = res;
      } else {
        this.$message.success("上传文件失败");
      }
    },
    //返回管理
    fanhui() {
      this.$router.push("/OwnerContractManagement");
    },
    Ti(){
      let loginid=sessionStorage.getItem("Id");
      let loginname=sessionStorage.getItem("Account");
      this.$axios.post("https://localhost:44399/api/app/owner-contract-shen/add-owner-contract?loginname="+loginname+"&loginid="+loginid+"",this.jieshu).then(res=>{
        if(res.data>0)
        {
          this.$message.success("提交成功");
        }
        else
        {
          this.$message.error("提交失败");
        }
      })
    }
  },
  created() {
    this.xianlu();
  },
};
</script>

<style>
</style>